<template>
    <div class="tpl-content-wrapper">
    <ol class="am-breadcrumb">
      <li><a href="#" class="am-icon-home">首页</a></li>
      <li><a href="#">管理用户</a></li>
      <li class="am-active">登录日志</li>
    </ol>
      <div class="tpl-portlet-components">
    <div class="tpl-block">
      <div class="am-g">
        <div class="am-u-sm-12">
          <form class="am-form">
            <table class="am-table am-table-striped am-table-hover table-main">
              <thead>
                <tr>
                  <th class="table-id">序号</th>
                  <th>账号</th>
                  <th>类型</th>
                  <th class="am-hide-sm-only">IP地址</th>
                  <th class="am-hide-sm-only">时间</th>
                </tr>
              </thead>
              <tbody>
                <tr v-for="(list, index) in lists">
                  <td>{{index + 1}}</td>
                  <td>{{list.acount}}</td>
                  <td>{{list.type === '1' ? '登陆' : '注销'}}</td>
                  <td class="am-hide-sm-only">{{list.ip}}</td>
                  <td class="am-hide-sm-only">{{list.ctime | date}}</td>
                </tr>
              </tbody>
            </table>
          </form>
          <pager :allCount="allCount" :count="count" :page="page" @changePage="changePage" @renovate="renovate"></pager>
        </div>
      </div>
    </div>
  </div>
  </div>
</template>

<script>
 import * as apis from '../../../apis'
 import excel from '../../../assets/excel'
  export default {
    data() {
      return {
        lists: [],
        fuzzy: '', sctime: '', ectime: '',
        count: 0,
        page: 1,
        pageSize: 20,
        ex: {name: '', page: 1, pageSum: 0}
      }
    },
    created() {
      this.getCount()
    },
    methods: {
      getCount() {
        apis.loginlogCount(this.fuzzy, this.sctime, this.ectime).then(({data: data}) => {
          console.log('data', data)
          if (data && data.errcode === 0) {
            this.allCount = data.data.count
            this.count = Math.ceil(data.data.count / this.pageSize)
            this.ex.pageSum = Math.ceil(data.data.count / 500)
            this.getLists()
          } else {
            this.lists = []
          }
        })
      },
      getLists() {
        apis.loginlogList(this.page, this.pageSize, this.fuzzy, this.sctime, this.ectime).then(({data: data}) => {
          if (data && data.errcode === 0) {

            this.lists = data.data.list
          }
        })
      },
      changePage(page) {
        this.page = page
        this.getLists()
      },
      onSearch() {
        this.page = 1
        this.getCount()
      },
       setSctime(val) {
        this.sctime = val
      },
      setEctime(val) {
        this.ectime = val
      },
      renovate (page) {
        this.getCount()
      },
      excelExport (name, page) {
        let col = {'acount': '账号', ctime: {name: '时间', time: 1}, ip: 'IP地址', type: {name: '类型', type: {'1': '登陆', '2': '注销'}}}
        apis.loginlogList(page, 500).then(({data: data}) => {
          if (data && data.result_code === 1 && data.result.loginlogList) {
            let rows = data.result.loginlogList
            excel.export(col, rows, name)
            this.ex.name = ''
            this.ex.page = 1
          }
        })
      }
    }
  }
</script>